#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "can.h"
#include <QMutex>
#include <QFuture>

QT_BEGIN_NAMESPACE
class Parameter;
class QThread;
QT_END_NAMESPACE

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();


signals:
    void change_paras(const QString&,const QString&,const QString&,const QString&,const QString&);

    void change_theme(int);

    void can_wrong();

    void y_data_changed();

    void change_progress2_value(int);

    void finish_continus_sample_save();

private slots:
    void on_pushButtonSingleSample_clicked();

    void on_pushButtonContinueSample_clicked();

//    void on_pushButtonOnlySend_clicked();

    void on_pushButtonContinueSampleSave_clicked();

    void on_pushButtonResetAxes_clicked();

    void on_action_2_triggered();

    void on_actionOrigin_triggered();

    void on_actionInstrument_triggered();

    void on_actionDark_triggered();

    void on_actionLight_triggered();

    void on_action_5_triggered();

    void on_action_triggered();

    void on_pushButtonModifyConfirm_clicked();

    void on_action_3_triggered();

    void on_action_6_triggered();

    void on_action_4_triggered();

    void deal_can_wrong();

    void deal_y_data_changed();

    void on_actionx_triggered();

    void deal_change_progress2_value(int);

    void deal_finish_continus_sample_save();

    void on_action_7_triggered();

    void on_action_8_triggered();

protected:
    void closeEvent(QCloseEvent *);

private:
    Ui::MainWindow *ui;
    Parameter *pm_window;
    Can* can;
    QList<double> x_pixels;
    QList<double> y_data;

    bool enable_con_sampe;
    int continus_sample_save_cnts;
    QList<QList<double>> y_data_multi_line;

    QMutex mutex;
    QFuture<void> future;

    unsigned long order_time; //ms, for QThread sleep
    int wait_time;//ms
    int len;// length of recieve data
    const int statusbar_time = 1500;//status bar message stay time
    const int surplus = 20;//add it to get data array

private:
    void update_ui(int);
    void initial_combox();
    void set_xPixels(const QString&);
    void set_timer(int);
    void can_communicate(bool save_file);
    void start_processbar();
    void continus_sample(Can *);
    void continus_sample_save(Can* can);
    bool send_get_datas(Can *can);
    void save_file();



//    bool only_send_data(Can*);

};

#endif // MAINWINDOW_H
